

function say() {
    alert("LC:54. 螺旋矩阵");
}
say();


//参考
//https://leetcode-cn.com/problems/spiral-matrix/solution/dong-hua-mo-ni-yi-xia-jiu-neng-gao-dong-i27qf/

/**
 * @param {number[][]} matrix
 * @return {number[]}
 */
var spiralOrder = function(matrix) {
    //9:34-50 // 10:18-35  //10:47-05
    //什么时候结束循环
    var left = 0
    var right = matrix[0].length - 1
    var top = 0
    var bottom = matrix.length - 1

    var res = []
    while(true){
        for(var i = left; i <= right; i++){
            res.push(matrix[top][i])
        }
        top ++
        if(top > bottom){
            break
        }

        for(var i = top; i <= bottom; i++){
            res.push(matrix[i][right])
        }
        right --
        if(left > right){
            break
        }

        for(var i = right; i >= left; i--){
            res.push(matrix[bottom][i])
        }
        bottom --
        if(top > bottom){
            break
        }

        for(var i = bottom; i >= top; i--){
            res.push(matrix[i][left])
        }
        left ++
        if(left > right){
            break
        }
    }

    return res
    
};
